package org.grow.enter.filter;

import org.springframework.stereotype.Service;
import org.springframework.web.servlet.function.ServerResponse;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Author: xwg
 * @CreateDate: 2021/9/8
 */

@Service
public class Third implements Filter {
    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        HttpServletRequest request = (HttpServletRequest) servletRequest;
        HttpServletResponse response = (HttpServletResponse) servletResponse;
//        http://localhost:8080/aaa/vvv
//        request.getRequestURL();
//        /aaa/vvv
        String requestURI = request.getRequestURI();
        System.out.println("第三过滤器拦截到："+requestURI);
        if (requestURI.contains("showPerson")){
            servletResponse.getWriter().println("abcd");
            return;
        }
        filterChain.doFilter(servletRequest, servletResponse);
        System.out.println("第三过滤器结束");
    }
//    如果只考虑上半部分 dofilter == next
//    使用filter写controller
}
